package com.shgbit.sdis.business;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shgbit.sdis.bean.DemoCity;
import com.shgbit.sdis.control.DemoController;
import com.shgbit.sdis.dao.DemoCityDao;
import com.shgbit.sdis.util.LogUtils;

@Service
public class DemoCityService {

	@Autowired 
	private DemoCityDao demoCityDao;
	
	/**
	 * 获取City列表信息
	 * add by liulinqing 2018-04-11
	 * @return City列表
	 */
    public List<DemoCity> getList(){
    	List <DemoCity> emptyList = null;
    	try {
    		emptyList =  demoCityDao.getEmpytList();
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "查询city列表信息出错";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return emptyList;
    }
    
    /**
     * add by liulinqing 2018-04-11
     * 根据ID查询City信息
     * @param id
     * @return
     */
    public DemoCity getDemoCityById(Integer id){
    	DemoCity city = new DemoCity();
    	try {
    		city = demoCityDao.getDemoCityById(id);
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "根据ID查询city信息出错";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return city;
    }
    
    /**
     * add by liulinqing 2018-04-17
     * 新增city信息
     * @param empty
     * @return
     */
    public int saveCityWithKey(DemoCity city){
    	int i = 0;
    	try {
			i = demoCityDao.saveEmptyWithSafe(city);
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "新增city出错";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return i;
    }
    
    /**
     * add by liulinqing 2018-04-17
     * 保存用户信息
     * @param city
     * @return
     */
    public int updateDemoCity(DemoCity city){
    	int i = 0;
    	try {
			i = demoCityDao.updateCity(city);
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "保存city信息出错！";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return i;
    }
    
    /**
     * add by liulinqing 2018-04-17
     * 删除city信息
     * @param city
     * @return
     */
    public int deleteDemoCity(DemoCity city){
    	int i = 0;
    	try {
			i = demoCityDao.deleteEmpty(city);
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "删除city信息异常！";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return i;
    }
    
    /**
     * add by liulinqing 2018-04-17
     * 根据Name获取City
     * @param city
     * @return
     */
    public DemoCity getDemoCityByName(DemoCity city){
    	DemoCity emptys = new DemoCity();
    	try {
			emptys = demoCityDao.getDemoCityByCityName(city);
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "根据用户名，查询city信息失败！";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return emptys;
    }
    
    /**
     * 获取用户数量
     * @return 用户数量
     */
    public Integer getCount(){
    	Integer i = 0;
    	try {
			i = demoCityDao.getCount();
		} catch (Exception e) {
			/*日志输出*/
			LogUtils.Log_Constant = "获取city数量异常！";
			LogUtils.LogOut("error");
			e.printStackTrace();
		}
    	return  i;
    }
}
